<%@ page import="com.ncf.jucai.accessmeter.AccessLog" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ncf.jucai.accessmeter.Counter" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <title>Jucai Access Meter</title>
</head>

<body>

<%
    List<AccessLog> mostCost = (List<AccessLog>) request.getAttribute("mostCostLogs");
    Map<String, Counter> costRangeMap = (Map<String, Counter>) request.getAttribute("costRangeMap");
    Map<String, Double> countRangeMap = (Map<String, Double>) request.getAttribute("countRangeMap");
    Double totalCount = (Double) request.getAttribute("totalCount");
%>

<h1>cost range count</h1>

<table border="5" cellpadding="4" cellspacing="3">
    <thead>
    <tr>
        <th>Cost(ms)</th>
        <th>Count</th>
        <th>Percentage</th>
    </tr>
    </thead>
    <tbody>
    <%
        for (Map.Entry<String, Counter> e : costRangeMap.entrySet()) {
    %>
    <tr>
        <td><%=e.getKey()%></td>
        <td><%=e.getValue().getCount()%></td>
        <td><%=e.getValue().getCount() / totalCount * 100%>%</td>
    </tr>
    <%
        }
    %>
    </tbody>
</table>

<h1>average cost of 10%</h1>

<table border="5" cellpadding="4" cellspacing="3">
    <thead>
    <tr>
        <th>Percentage</th>
        <th>Average Cost</th>
    </tr>
    </thead>
    <tbody>
    <%
        for (Map.Entry<String, Double> e : countRangeMap.entrySet()) {
    %>
    <tr>
        <td><%=e.getKey()%></td>
        <td><%=e.getValue()%></td>
    </tr>
    <%
        }
    %>
    </tbody>
</table>

<h1>most cost top list</h1>

<table border="5" cellpadding="4" cellspacing="3">
    <thead>
    <tr>
        <th>Cost</th>
        <th>URL</th>
    </tr>
    </thead>
    <tbody>
    <%
        for (AccessLog al : mostCost) {
    %>
    <tr>
        <td><%=al.getCost()%> ms</td>
        <td><%=al.getPath() + (al.getQuery() == null ? "" : al.getQuery())%></td>
    </tr>
    <%
        }
    %>
    </tbody>
</table>

</body>

</html>
